from django.db import models
from django.contrib.auth.models import User


# Create your models here.


class UserInformationModel(models.Model):
    class Meta:
        db_table = "user_information"
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    qq = models.CharField(max_length=10, verbose_name='QQ号', db_index=True)
    available = models.BooleanField(default=True, verbose_name="可用")
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户', null=True, related_name="information")
    def __str__(self):
        return str(self.user)


class GroupModel(models.Model):
    class Meta:
        db_table = "user_group"
        verbose_name = "分组"
        verbose_name_plural = verbose_name

    name = models.CharField(max_length=30, verbose_name="组名")
    desc = models.TextField('描述', default='', blank=True, null=True, max_length=200)
    owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='创建人', null=True, related_name="own_groups")
    managers = models.ManyToManyField(User, verbose_name="管理员", related_name="manage_groups")
    members = models.ManyToManyField(User, verbose_name="成员", related_name="member_groups")
    def __str__(self):
        return str(self.name)
